Repository navigation
fix(items): keep inline entries before AoT and table sections when sorting keys - #730
Open
ghanashyam03 wants to merge 1 commit into
Open
ghanashyam03 wants to merge 1 commit into
ghanashyam03 wants to merge 1 commit into
Conversation
|
🛡️ Human Attestation required. A human needs to confirm this PR once before it can merge. Attest this PR — sign in with GitHub, pass the challenge, and confirm one of the statements. |
Giacomo117
reviewed
Dec 4, 2026
Giacomo117
left a comment
There was a problem hiding this comment.
Nice catch, this one actually changes data silently, so it's a good one to fix.
I tried it on top of current master: merges cleanly, full suite passes, and the new test fails without the change. I also threw a few more shapes at sort_keys=True (sub-tables, two AoTs, an AoT with its own sub-table, top-level AoT). On master most of them come back different, e.g.
[t]
z = 1
[[t.a]]
x = 2
turns into z living inside [[t.a]]. With your branch they all round-trip fine.
Only thing I'd add is a line in CHANGELOG.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_opens_container_sectionintomlkit/items.pyand updated_sort_container_bodyto classifyAoTand section-openingTableitems separately from inline values (InlineTable, scalars, and inline dotted-key super tables).tests/test_api.pycoveringAoTinside tables and nestedAoTs, mixedAoT/sub-table ordering, inline tables, and dotted keys underdumps(..., sort_keys=True).Motivation
Previously,
_sort_container_bodyusedisinstance(value, dict)to push section headers after inline entries. BecauseAoTsubclasses_CustomListrather thandict, andInlineTable/ inline dotted-key super tables subclassdict, sorting could place[[aot]]or[table]headers before inline keys and move parent entries into the following section.Fixes #729.
Testing
ruff check tomlkit tests/test_api.py(passed)ruff format --check tomlkit/items.py tests/test_api.py(passed)python -m pytest -p no:remotedata -q tests(1485 passed)